const cloud = require("@cloudbase/node-sdk");

const app = cloud.init({
    env: cloud.SYMBOL_CURRENT_ENV,
});

var db = app.database();
const $ = db.command.aggregate
const _ = db.command
const nowDate = db.serverDate()

const AION_Msg = db.collection('AION-Message')

// 获取openId云函数入口函数
exports.main = async (event, context) => {

    // return await AION_ZB_WQ.get()
    
    var type = event.data.type
    var content = event.data.content
    var status = event.data.status
    var title = event.data.title
    var params = {}

    params.title = title
    params.content = content
    params.status = status
    params.createTime = nowDate

    if(type=='addMsg'){
        
        const res = await AION_Msg.add(params)
        return {
            id: res.id
        };
    }

    if(type=='getMsg'){
        const res = await AION_Msg.where({
            status: 1,
        })
        .get()
        return res
    }

};
